package com.atguigu.tingshu.payment.api;

import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.payment.service.WxPayService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "微信支付接口")
@RestController
@RequestMapping("api/payment")
@Slf4j
public class WxPayApiController {

    @Autowired
    private WxPayService wxPayService;


    @PostMapping("/wxPay/createJsapi/{paymentType}/{orderNo}")
    @GuiGuLogin
    public Result<Map<String,Object>> createJsapi(@PathVariable String paymentType,@PathVariable String orderNo){
        Long userId = AuthContextHolder.getUserId();
        Map<String,Object> resultMap = wxPayService.createJsapi(paymentType,orderNo,userId);
        return Result.ok(resultMap);
    }
}
